﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
[assembly: CLSCompliant(true)]
namespace Statistic
{ 
    public partial class MainForm : Form
    {
        private IList<string> keyWords_ = new List<string>();
        private string date_;
        Thread oThread;

        public MainForm()
        {
            InitializeComponent();   
        }

        public void SetUserPreferences()
        {    
            for(int i = 0; i < listBox1.Items.Count; i++)
            {
                keyWords_.Add(listBox1.Items[i].ToString());
            }        
            date_ = dateTBox.Text;
        }

        private void addBtn_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(keyWTBox.Text.ToString());
        }

        private void startWithXml_Click(object sender, EventArgs e)
        {
            SetUserPreferences();
            StatsAnalyzer statsAnalyzer = new StatsAnalyzer(keyWords_, date_);
            statsAnalyzer.ReadXml(xmlTBox.Text);
        }

        private void startBtn_Click(object sender, EventArgs e)
        {
            SetUserPreferences();
            Worker worker = new Worker(keyWords_, date_);

            if (checkedListBox1.GetItemCheckState(0).ToString() == "Checked")
            {
                IReader reader = new CareerReader();
                worker.AddReader(reader);
            }
            if (checkedListBox1.GetItemCheckState(1).ToString() == "Checked")
            {
                IReader reader = new SkyWalkerReader();
                worker.AddReader(reader);
            }

            oThread = new Thread(new ThreadStart(worker.DoIt));
            oThread.Start();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (oThread != null)
            oThread.Abort();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
